package leetcode.algorithms.贪心算法;

import java.util.Arrays;

/**
 * 贪心思想：把孩子的胃口和饼干的尺寸排序，最低限度满足孩子的胃口，
 */
public class ACode455 {

    public static int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);

        int childIndex = 0;
        int cookieIndex = 0;
        while(childIndex < g.length && cookieIndex < s.length){
            if(g[childIndex] <= s[cookieIndex]){
                childIndex++;
            }
            cookieIndex++;
        }
        return childIndex;
    }

    public static void main(String[] args) {
        int[] g = new int[]{1,2};
        int[] s = new int[]{1,2,3};
        System.out.println(findContentChildren(g,s));
    }

}
